package com.sos.service;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.sos.util.HttpUtil;
import com.sos.vo.SosInfo;
/***
 * 网站后台通讯服务
 * */
public class WWWService {
	private Context context;
	//private String imsi="";
	private final static String TAG = WWWService.class.getSimpleName();
	public WWWService(){
		
	}
	public WWWService(Context context){
		this.context=context;
	}
	public String getImsi()
	{
		TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		String imsi = tm.getSubscriberId();
		return imsi;


	} 
	public String getPhone()
	{
		TelephonyManager telephonyMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
	     String tel = telephonyMgr.getLine1Number();
		return tel; 

	}
	public String  putSosInfo(String ip,String port,SosInfo sosinfo)
	{
		
		sosinfo.setSoPhoneId(getImsi());
		//sosinfo.setSoUserPhone(getPhone());
		//String url="http://"+ip+":"+port+"/sos/sos?"+sosinfo.toString();
		
		String ret="";
		//ret=HttpUtil.httpRequestInfo(url);
		String url="http://"+ip+":"+port+"/sos/sos";
		Log.d(TAG, url);
		HttpUtil.httpPost(sosinfo.toPar(), url);
		Log.d(TAG, "ret:"+ret);
		return ret;
	}
	
	public String loaction(String lon,String lng,String ip,String port)
	{
		String ret="";
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("lon",lon));
		params.add(new BasicNameValuePair("lat",lng));
		params.add(new BasicNameValuePair("phoneId",getImsi()));
		String url="http://"+ip+":"+port+"/sos/location";
		Log.d(TAG, url);
		HttpUtil.httpPost(params, url);
		Log.d(TAG, "ret:"+ret);
		return ret;
	}
	
}
